package com.eschool.controller;

import com.eschool.pojo.*;
import com.eschool.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Configuration
public class CourseController {
    @Autowired
    CourseService courseService;

    @RequestMapping("/course/getAllCourse")
    public ServerResult getAllCourse(){
        List<CourseDAO>  courseList = courseService.getAllCourse();
        return new ServerResult(0,"success",courseList);
    }

    @RequestMapping("/course/chooseCourse")
    public ServerResult chooseCourse(ChooseCourseDTO chooseCourseDTO){
        int updateRow = courseService.ChooseCourse(chooseCourseDTO);
        if(updateRow==-1){
            return new ServerResult(500,"grade wrong",null);
        }
        else if(updateRow==0){
            return new ServerResult(200,"fail",null);
        }
        else{
            return new ServerResult(0,"success",null);
        }
    }

    @RequestMapping("/course/getChoosenCourse")
    public ServerResult getChoosenCourse(Integer stuid){
        List<CourseDAO> courseDAOS = courseService.getChoosenCourses(stuid);
        return new ServerResult(0,"success",courseDAOS);
    }

    @RequestMapping("/course/deleteCourse")
    public ServerResult DeleteCourse(Integer stuid,Integer courseid){
        int  updateRow = courseService.DeleteCourse(stuid,courseid);
        if(updateRow>0){
            return new ServerResult(0,"success",null);
        }
        else{
            return new ServerResult(200,"fail",null);
        }
    }

    @RequestMapping("/course/getCourseByInfo")
    public ServerResult getCourseByInfo(getCourseByInfoDTO getCourseByInfoDTO){
        List<CourseDAO> courseDAOS = courseService.getCourseByInfo(getCourseByInfoDTO);
        if(courseDAOS.size()==0){
            return new ServerResult(500,"没有查询到任何结果！",null);
        }
        else{
            return new ServerResult(0,"success",courseDAOS);
        }
    }

    @RequestMapping("/score/getScoreByInfo")
    public ServerResult getScoreByInfo(ScoreDTO  scoreDTO){
        List<ScoreDAO> scoreDAOS = courseService.getScoresByInfo(scoreDTO);
        if(scoreDAOS.size()==0){
            return new ServerResult(200,"没有查询到成绩结果",null);
        }
        else {
            return new ServerResult(0,"success",scoreDAOS);
        }
    }
}
